/*
 * FAConstraintModel.cpp
 *
 *      Author: Jerome RD Soine and Christoph A Brand
 *      Institution: Schwarz goup, Institute for Theoretical Physics, Heidelberg University, Germany
 */

#include "../../../../include/base/cell_models/FAConstraint/FAConstraintModel.h"
#include "../../../../include/core/shape/Ellipse.h"
#include "../../../../include/core/shape/Rectangle.h"
#include "../../../../include/core/shape/Square.h"
#include "../../../../include/core/shape/Circle.h"
#include "../../../../include/core/shape/Shape.h"
#include <iostream>
#include <stdlib.h>



FAConstraintModel::FAConstraintModel(string FILENAME, unsigned int TYPE)
{
	filename = FILENAME;
	type = TYPE;

	vector<Shape*> shapes;
	if(TYPE == Shape::TYPE_ELLIPSE)
		shapes = Ellipse::get_shapes_from_file(FILENAME);
	else if (TYPE == Shape::TYPE_RECTANGLE)
		shapes = Rectangle::get_shapes_from_file(FILENAME);
	else if (TYPE == Shape::TYPE_CIRCLE)
		shapes = Circle::get_shapes_from_file(FILENAME);
	else if (TYPE == Shape::TYPE_SQUARE)
		shapes = Square::get_shapes_from_file(FILENAME);
	else {cout << "ERROR: WRONG SHAPE TYPE \n"; exit(0);}

	unsigned int n_FAs = shapes.size();

	vector<Shape*> new_shapes;
	if(TYPE == Shape::TYPE_ELLIPSE)
	{
		for(unsigned int i=0;i<shapes.size();i++)
		{
			new_shapes.push_back(Circle::convert_from_ellipse((Ellipse*)shapes[i]));
		}
	}

	vector<double> tmp_p (n_FAs*2,0);
	set_parameters(tmp_p);
	tmp_p.resize(2);

	if(TYPE == Shape::TYPE_ELLIPSE)
	{
		for(unsigned int i=0;i<n_FAs;i++)
		{
			tmp_p[0] = parameters[i*2];
			tmp_p[1] = parameters[i*2+1];
			force_transmissions.push_back(new ForceTransmission(tmp_p,new_shapes[i]));
		}
	}
	else{
		for(unsigned int i=0;i<n_FAs;i++)
		{
			tmp_p[0] = parameters[i*2];
			tmp_p[1] = parameters[i*2+1];
			force_transmissions.push_back(new ForceTransmission(tmp_p,shapes[i]));
		}
	}
}

void FAConstraintModel::run()
{
	vector<double> tmp (2,0);
	for(unsigned int i=0;i<force_transmissions.size();i++)
	{
			tmp[0] = parameters[i*2];
			tmp[1] = parameters[i*2+1];
			force_transmissions[i]->set_force(tmp);
			cout << "ft " << i <<": totforce = " << force_transmissions[i]->get_force_magnitude() << endl;
	}



}
